﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace SRM.Core.Utility
{
    /// <summary>
    /// AOP
    /// </summary>
    public class CustomExceptionFilterAttribute: ExceptionFilterAttribute
    {
        public override void OnException(ExceptionContext context)
        {
            base.OnException(context);

            //context.ExceptionHandled 异常被处理
            if (!context.ExceptionHandled)
            {
                Console.WriteLine($"{context.HttpContext.Request.Path}---{context.Exception.Message}");

                RedirectResult redirectResult = new RedirectResult($"/Error/Index/{context.Exception}");
                context.Result = redirectResult;
            }
            context.ExceptionHandled = true;
        }
    }
}
